package com.example.mycontact.DB

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.util.Log
import kotlin.math.log

class MyDBHelper(var context: Context)
    : SQLiteOpenHelper(context,"ContactDB",null,1) {
    override fun onCreate(db: SQLiteDatabase?) {
        //数据库创建的时候执行，只执行一次 创建一些初始表
        val createTable = "create table Contacts(" +
                "id integer primary key autoincrement," +
                "name text not null," +
                "company text," +
                "position text," +
                "tel text," +
                "email text," +
                "image blob" +")"
        //执行创建表的SQL
        db?.execSQL(createTable)
        Log.i("MyDBHelper","contacts数据库创建成功")

    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        //数据库版本更新
    }

}